<?php

    namespace app\member\controller;


    use app\common\utils\UtilRedisBase;
    use app\face2market\logic\SendMessageRedis;

    use app\member\model\MessageModel;
    use think\Controller;


    /**
     * 定时任务接口
     * Class Autotask
     * @package app\face2market\controller
     */
    class Autotask extends Controller
    {
        public function send()
        {
            (new SendMessageRedis())->run();
        }

        public function send_one()
        {
            $Redis = UtilRedisBase::getInstance(config('redis'));
            while (true) {
                $message = json_decode($Redis->lPop('message_one'), true);
                dump($message);
                switch ($message['type']) {
                    case 'sms'://短消息
                        (new SendMessageRedis())->send_one($Redis, $message['phone'], $message['content']);
                        break;
                    case 'sys_sms'://系统消息
                        ;
                        MessageModel::create([
                            'type' => 1,
                            'title' => '系统提示',
                            'content' => $message['content'],
                            'member_id' => $message['member_id']
                        ]);
                        break;
                    default:
                        sleep(5);
                }
            }
        }
    }